package com.example.oj.controller;

import com.example.oj.entity.QuestionAnswer;
import com.example.oj.entity.dto.questionAnswer.AnswerSaveRequest;
import com.example.oj.entity.vo.QuestionAnswerVO;
import com.example.oj.service.QuestionAnswerService;
import com.example.ojcommon.common.BaseResponse;
import com.example.ojcommon.common.ResultUtils;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("/answer")
public class QuestionAnswerController {

  @Resource
  private QuestionAnswerService questionAnswerService;

  @GetMapping("/getById")
  public BaseResponse<QuestionAnswerVO> getAnswerVOById(Long questionId, HttpServletRequest request) {
    QuestionAnswer answer = questionAnswerService.getByQuestionId(questionId);
    QuestionAnswerVO answerVO = questionAnswerService.getAnswerVO(answer);
    return ResultUtils.success(answerVO);
  }

  @PostMapping("/add")
  public BaseResponse<Integer> addAnswer(@RequestBody AnswerSaveRequest saveRequest, HttpServletRequest request) {
    Integer res = questionAnswerService.addAnswer(saveRequest);
    return ResultUtils.success(res);
  }

}
